﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Microsoft.ApplicationBlocks.Data;
using System.Configuration;

namespace Customs.Components.GC
{
	/// <summary>
	/// Loại sản phẩm.
	/// </summary>
	public class LoaiSanPham
	{
		public static DataSet GetDanhSachNhomSPOfHopDong(string maHaiQuan, string maDoanhNghiep, string soHD, DateTime ngayKy)
		{
			string connectionString = ConnectionManager.GetConnectionString("SLXNK", maHaiQuan);
			StringBuilder query = new StringBuilder();
			query.Append("SELECT ");
			query.Append("LSP.So_HD			AS SoHopDong, ");
			query.Append("LSP.Ma_HQHD		AS MaHaiQuan, ");
			query.Append("LSP.DVGC			AS MaDoanhNghiep, ");
            query.Append("LSP.Ngay_Ky		AS NgayKy, ");
			query.Append("LSP.Ma_SPGC		AS Ma, ");
			query.Append("LSP.So_Luong		AS SoLuong, ");
			query.Append("LSP.Gia_GC		AS Gia ");
			query.Append("FROM DLOAISPGC LSP ");
			query.Append("WHERE ");
			query.Append("LSP.Ma_HQHD = @MaHaiQuan AND ");
			query.Append("LSP.DVGC = @MaDoanhNghiep AND ");
			query.Append("LSP.So_HD = @SoHopDong AND ");
            query.Append("LSP.Ngay_Ky = @NgayKy ");			

			SqlParameter[] parameters = new SqlParameter[4];

			parameters[0] = new SqlParameter("@MaHaiQuan", SqlDbType.Char, 6);
			parameters[0].Value = maHaiQuan;

			parameters[1] = new SqlParameter("@MaDoanhNghiep", SqlDbType.VarChar, 14);
			parameters[1].Value = maDoanhNghiep;

			parameters[2] = new SqlParameter("@SoHopDong", SqlDbType.VarChar, 50);
			parameters[2].Value = soHD;

			parameters[3] = new SqlParameter("@NgayKy", SqlDbType.DateTime);
			parameters[3].Value = ngayKy;

			return SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query.ToString(), parameters);
		}

        public static DataSet GetDanhSach(string maHaiQuan, string maDoanhNghiep)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString_SLXNK"].ConnectionString;
            StringBuilder query = new StringBuilder();
            query.Append("SELECT ");
            query.Append("LSP.So_HD			AS SoHopDong, ");
            query.Append("LSP.Ma_HQHD		AS MaHaiQuan, ");
            query.Append("LSP.DVGC			AS MaDoanhNghiep, ");
            query.Append("LSP.Ngay_Ky		AS NgayKy, ");
            query.Append("LSP.Ma_SPGC		AS Ma, ");
            query.Append("LSP.So_Luong		AS SoLuong, ");
            query.Append("LSP.Gia_GC		AS Gia ");
            query.Append("FROM DLOAISPGC LSP ");
            query.Append("WHERE ");
            query.Append("LSP.Ma_HQHD = @MaHaiQuan AND ");
            query.Append("LSP.DVGC = @MaDoanhNghiep  ");
           
            SqlParameter[] parameters = new SqlParameter[2];

            parameters[0] = new SqlParameter("@MaHaiQuan", SqlDbType.Char, 6);
            parameters[0].Value = maHaiQuan;

            parameters[1] = new SqlParameter("@MaDoanhNghiep", SqlDbType.VarChar, 14);
            parameters[1].Value = maDoanhNghiep;
           
            return SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query.ToString(), parameters);
        }

	}
}
